from aiogram_dialog import DialogManager
from fluentogram import TranslatorRunner

from poker_bot.database.services import (
    AccountService,
    PaymentMethodService,
    UserService,
    WithdrawService,
)


async def all_withdraws_getter(
    dialog_manager: DialogManager, withdraw_service: WithdrawService, **kwargs
):
    all_withdraws = await withdraw_service.get_all_withdrawals()

    return {"all_withdraws": all_withdraws}


async def unconfirmed_withdraws_getter(
    dialog_manager: DialogManager, withdraw_service: WithdrawService, **kwargs
):
    unconfirmed_withdraws = await withdraw_service.get_withdrawals_for_confirmation()

    return {"unconfirmed_withdraws": unconfirmed_withdraws}


async def withdraw_info_getter(
    dialog_manager: DialogManager,
    locale: TranslatorRunner,
    withdraw_service: WithdrawService,
    user_service: UserService,
    account_service: AccountService,
    payment_method_service: PaymentMethodService,
    **kwargs
):
    withdraw_id: int = dialog_manager.dialog_data.get("withdraw_id")

    withdraw = await withdraw_service.get_withdraw_by_id(withdraw_id)
    user = await user_service.get_user_by_id(withdraw.user_id)
    account = await account_service.get_account_by_id(user.selected_account_id)
    payment_method = await payment_method_service.get_payment_method_by_id(
        withdraw.payment_method_id
    )

    return {
        "withdraw_id": withdraw.id,
        "account_id": account.account_id,
        "status": withdraw.status,
        "summ": withdraw.summ,
        "username": user.username,
        "user_tg_id": user.telegram_id,
        "currency_symbol": withdraw.currency_symbol,
        "payment_address": withdraw.payment_address,
        "payment_method": locale.get(withdraw.currency.value),
        "status_value": locale.get(withdraw.status.value),
        "was_created": withdraw.created_at,
    }
